<%@ page import="com.casework.*" %>
<!doctype html>
<html>
    <head>
        <meta name="layout" content="main">
        <g:set var="entityName" value="${message(code: 'legalCase.label', default: 'Case')}" />
        <title><g:message code="default.show.label" args="[entityName]" /></title>
    </head>
    <body>
        <a href="#show-legalCase" class="skip" tabindex="-1"><g:message code="default.link.skip.label" default="Skip to content&hellip;"/></a>
<sec:ifAllGranted roles="ROLE_ADMIN">
        <div class="nav" role="navigation">
            <ul>
                <li><a class="home" href="${createLink(uri: '/')}"><g:message code="default.home.label"/></a></li>
                <li><g:link class="list" action="list"><g:message code="default.list.label" args="[entityName]" /></g:link></li>
                <li><g:link class="create" action="create"><g:message code="default.new.label" args="[entityName]" /></g:link></li>
            </ul>
        </div>
</sec:ifAllGranted>
        <div id="show-legalCase" class="content scaffold-show" role="main">
            <h1><g:message code="default.show.label" args="[entityName]" /></h1>
            <g:if test="${flash.message}">
            <div class="message" role="status">${flash.message}</div>
            </g:if>
            <ol class="property-list legalCase">

                <g:if test="${legalCaseInstance?.ecNumber}">
                    <li class="fieldcontain">
                        <span id="ecNumber-label" class="property-label"><g:message code="legalCase.ecNumber.label" default="EC Number" /></span>
                        <span class="property-value" aria-labelledby="ecNumber-label">M.${legalCaseInstance.ecNumber}</span>
                    </li>
                </g:if>


                <li class="fieldcontain list-of-data">
                    <span id="offers-firms" class="property-label"><g:message code="legalCase.firs.label" default="Notifying Parties" /></span>

                    <g:each in="${firms}" var="o">
                        <span class="property-value" aria-labelledby="offers-firms">
                            <g:link controller="firm" action="show" id="${o.id}">${o?.encodeAsHTML()}</g:link>
                            <sec:ifAllGranted roles="ROLE_ADMIN">
                                <a href="#" class="close-button" data-name="Firm" data-id="${o.id}">x</a>
                            </sec:ifAllGranted>
                        </span>
                    </g:each>

                    <sec:ifAllGranted roles="ROLE_ADMIN">
                        <g:select from="${Firm.list()}" optionKey='id' id='select-firm' class='data-selector'/>
                        <a href="#" id='add-firm'>Add</a>
                        <g:link action="create" controller="firm" params="[caseId:legalCaseInstance.id]">Create</g:link>
                    </sec:ifAllGranted>
                </li>

                <li class="fieldcontain list-of-data">
                    <span id="offers-nace" class="property-label"><g:message code="legalCase.nace.label" default="NACE" /></span>

                    <g:each in="${descriptions}" var="o">
                        <span class="property-value" aria-labelledby="offers-nace">
                            <g:link controller="nace" action="show" id="${o.id}">${o?.encodeAsHTML()}</g:link>
                            <sec:ifAllGranted roles="ROLE_ADMIN">
                                <a href="#" class="close-button" data-name="Nace" data-id="${o.id}">x</a>
                            </sec:ifAllGranted>
                        </span>

                    </g:each>

                    <sec:ifAllGranted roles="ROLE_ADMIN">
                        <g:select from="${Nace.list()}" optionKey='id' id='select-nace' class='data-selector'/>
                        <a href="#" id='add-nace'>Add</a>
                        <g:link action="create" controller="nace" params="[caseId:legalCaseInstance.id]">Create</g:link>
                    </sec:ifAllGranted>
                </li>

                <g:if test="${legalCaseInstance?.phase}">
                <li class="fieldcontain">
                    <span id="phase-label" class="property-label"><g:message code="legalCase.phase.label" default="Phase" /></span>

                        <span class="property-value" aria-labelledby="phase-label"><g:fieldValue bean="${legalCaseInstance}" field="phase"/></span>

                </li>
                </g:if>

                <g:if test="${legalCaseInstance?.notificationDate}">
                <li class="fieldcontain">
                    <span id="notificationDate-label" class="property-label"><g:message code="legalCase.notificationDate.label" default="Notification Date" /></span>
                    <span class="property-value" aria-labelledby="notificationDate-label"><g:fieldValue bean="${legalCaseInstance}" field="notificationDate"/></span>
                </li>
                </g:if>

                <g:if test="${legalCaseInstance?.decisionDate}">
                <li class="fieldcontain">
                    <span id="decisionDate-label" class="property-label"><g:message code="legalCase.decisionDate.label" default="Decision Date" /></span>
                    <span class="property-value" aria-labelledby="decisionDate-label"><g:fieldValue bean="${legalCaseInstance}" field="decisionDate"/></span>
                </li>
                </g:if>

                <li class="fieldcontain">
                    <span id="competitionConcern-label" class="property-label"><g:message
                            code="legalCaseInstance.competitionConcern.label" default="Competition Concern"/></span>
                    <span class="property-value" aria-labelledby="competitionConcern-label">
                        <g:fieldValue
                            bean="${legalCaseInstance}" field="competitionConcern"/></span>
                </li>

                <g:if test="${legalCaseInstance?.article}">
                <li class="fieldcontain">
                    <span id="article-label" class="property-label"><g:message code="legalCase.article.label" default="Article" /></span>
                    <span class="property-value" aria-labelledby="article-label"><g:fieldValue bean="${legalCaseInstance}" field="article"/></span>
                </li>
                </g:if>

                <g:if test="${legalCaseInstance?.ph1Offer}">
                <li class="fieldcontain">
                    <span id="ph1Offer-label" class="property-label"><g:message code="legalCase.ph1Offer.label" default="Ph1 Offer" /> <casework:tooltip title="${g.message(code:'balloon.ph1Offer')}" /></span>
                    <span class="property-value" aria-labelledby="ph1Offer-label"><g:fieldValue bean="${legalCaseInstance}" field="ph1Offer"/></span>
                </li>
                </g:if>

                <g:if test="${legalCaseInstance?.dateOfStatementOfObjections}">
                <li class="fieldcontain">
                    <span id="dateOfStatementOfObjections-label" class="property-label"><g:message code="legalCase.dateOfStatementOfObjections.label" default="Date Of Statement Of Objections" /></span>
                    <span class="property-value" aria-labelledby="dateOfStatementOfObjections-label"><g:fieldValue bean="${legalCaseInstance}" field="dateOfStatementOfObjections"/></span>
                </li>
                </g:if>

                <g:if test="${legalCaseInstance?.relativeToSO}">
                <li class="fieldcontain">
                    <span id="relativeToSO-label" class="property-label"><g:message code="legalCase.relativeToSO.label" default="Relative To SO" /></span>
                    <span class="property-value" aria-labelledby="relativeToSO-label"><g:fieldValue bean="${legalCaseInstance}" field="relativeToSO"/></span>
                </li>
                </g:if>

                <g:if test="${legalCaseInstance?.typeA}">
                <li class="fieldcontain">
                    <span id="typeA-label" class="property-label"><g:message code="legalCase.typeA.label" default="Type A" /> <casework:tooltip title="${g.message(code:'balloon.type.a')}" /></span>
                    <span class="property-value" aria-labelledby="typeA-label"><g:fieldValue bean="${legalCaseInstance}" field="typeA"/></span>
                </li>
                </g:if>

                <g:if test="${legalCaseInstance?.typeB}">
                <li class="fieldcontain">
                    <span id="typeB-label" class="property-label"><g:message code="legalCase.typeB.label" default="Type B" /> <casework:tooltip title="${g.message(code:'balloon.type.b')}" /></span>
                    <span class="property-value" aria-labelledby="typeB-label"><g:fieldValue bean="${legalCaseInstance}" field="typeB"/></span>
                </li>
                </g:if>

                <g:if test="${legalCaseInstance?.dealType}">
                <li class="fieldcontain">
                    <span id="dealType-label" class="property-label"><g:message code="legalCase.dealType.label" default="Deal Type" /></span>
                    <span class="property-value" aria-labelledby="dealType-label">${legalCaseInstance?.dealType?.encodeAsHTML()}</span>
                </li>
                </g:if>

                <g:if test="${legalCaseInstance?.measures}">
                <li class="fieldcontain">
                    <span id="measures-label" class="property-label"><g:message code="legalCase.measures.label" default="Measures" /></span>
                        <ul>
                        <g:each in="${legalCaseInstance.measures}" var="m">
                            <span class="property-value" aria-labelledby="measures-label">
                                <li class="description">
                                    <g:link controller="measure" action="show" id="${m.id}">${m.fullMeasureDescription}</g:link>
                                    <sec:ifAllGranted roles="ROLE_ADMIN">
                                        <a href="#" class="close-button" data-name="Measure" data-id="${m?.id}">x</a>
                                    </sec:ifAllGranted>
                                </li>
                            </span>
                        </g:each>
                        </ul>

                </li>
                </g:if>

                <sec:ifAllGranted roles="ROLE_ADMIN">
                <li class="fieldcontain"><span class="property-label"></span>
                    <g:if test="${!legalCaseInstance.measures}">
                        <span id="measures-label" class="property-label"><g:message code="legalCase.measures.label"
                                                                                    default="Measures"/></span>
                    </g:if>

                    <span class="property-value" aria-labelledby="measures-label">
                        <g:link action="create" controller="measure" params="[caseId:legalCaseInstance.id]">Add Measure</g:link>
                    </span>
                </li>
                </sec:ifAllGranted>


                <g:if test="${legalCaseInstance?.offers}">
                <li class="fieldcontain">
                    <span id="offers-label" class="property-label"><g:message code="legalCase.offers.label" default="Offers" /> <casework:tooltip title="${g.message(code:'balloon.offers')}" /></span>

                        <g:each in="${legalCaseInstance.offers}" var="o">
                        <span class="property-value" aria-labelledby="offers-label">
                            ${o?.encodeAsHTML()}
                            <sec:ifAllGranted roles="ROLE_ADMIN">
                                <a href="#" class="close-button" data-name="Offer" data-id="${o.id}">x</a>
                            </sec:ifAllGranted>
                        </span>
                        </g:each>

                </li>
                </g:if>

                <sec:ifAllGranted roles="ROLE_ADMIN">
                <li class="fieldcontain"><span class="property-label"></span>
                    <g:if test="${!legalCaseInstance.offers}">
                        <span id="offers-label" class="property-label"><g:message code="legalCase.offers.label"
                                                                                  default="Offers"/></span>
                    </g:if>
                    <span class="property-value" aria-labelledby="measures-label">
                        <g:link action="create" controller="offer" params="[caseId:legalCaseInstance.id]">Add Offer</g:link>
                    </span>
                </li>
                </sec:ifAllGranted>

                <g:if test="${legalCaseInstance?.commentOnOffers}">
                    <li class="fieldcontain">
                        <span id="commentOnOffers-label" class="property-label"><g:message
                                code="legalCaseInstance.commentOnOffers.label" default="Comments"/></span>
                        <span class="property-value" aria-labelledby="comments-label">${legalCaseInstance?.commentOnOffers}</span>


                    </li>
                </g:if>

                <g:render template="attachedFiles" model="[legalCaseInstance: legalCaseInstance]"/>

            </ol>
<sec:ifAllGranted roles="ROLE_ADMIN">
            <g:form>
                <fieldset class="buttons">
                    <g:hiddenField name="id" value="${legalCaseInstance?.id}" />
                    <g:link class="edit" action="edit" id="${legalCaseInstance?.id}"><g:message code="default.button.edit.label" default="Edit" /></g:link>
                    <g:actionSubmit class="delete" action="delete" value="${message(code: 'default.button.delete.label', default: 'Delete')}" onclick="return confirm('${message(code: 'default.button.delete.confirm.message', default: 'Are you sure?')}');" />
                </fieldset>
            </g:form>
</sec:ifAllGranted>

        </div>

    <r:script>
        $('.tooltip').tipsy();
        $('.close-button').css('visibility', 'visible');
        $('.close-button').click(function(e){

            var domainClassName = $(e.target).data('name');
            var id = $(e.target).data('id');
            var element = e.target
            $.ajax({
                type: 'POST',
                url: "${request.getContextPath()}/legalCase/delete"+domainClassName,
                data: {'id': id, 'caseId': "${legalCaseInstance.id}"},
                success: function(msg){
                 $(element).parent('.property-value').remove();
                 $(element).parent('.description').remove();

                },
                error: function(e, xhr, status){
                    alert('Error connecting to server');
                }
             })
             return false;
        })


        jQuery('#add-firm').click(function(){
            jQuery.ajax({
                type: 'POST',
                url: "${request.getContextPath()}/legalCase/addFirm",
                data: {'caseId': "${legalCaseInstance.id}", 'firmId': jQuery('#select-firm').val()},
                success: function(msg){
                 $('#select-firm').before(msg);
                },
                error: function(e, xhr, status){
                    alert('Error connecting to server');
                }
            })
            return false;
        });

        jQuery('#add-nace').click(function(){
            jQuery.ajax({
                type: 'POST',
                url: "${request.getContextPath()}/legalCase/addNace",
                data: {'caseId': "${legalCaseInstance.id}", 'naceId': jQuery('#select-nace').val()},
                success: function(msg){
                 $('#select-nace').before(msg);
                },
                error: function(e, xhr, status){
                    alert('Error connecting to server');
                }
            })
            return false;
        });
    </r:script>
    </body>
</html>
